package cn.org.july.weixin.common.bean.message;

import cn.org.july.weixin.common.utils.XmlUtils;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Map;

/**
 * 回复图文消息对象类
 *
 * @auther: wanghongjie
 * @blame: wanghongjie
 * @date: 2020-08-31 21:42
 * @Description:
 */
@Setter
@Getter
@XStreamAlias("xml")
public class ArticleMessage extends BaseMessage {
    /**
     * 图文消息个数
     */
    @XStreamAlias("ArticleCount")
    private String articleCount;
    /**
     * 图文消息内容
     */
    @XStreamAlias("Articles")
    private List<Article> articles;

    public static ArticleMessage of(Map<String, Object> objectMap, List<Article> articles) {
        ArticleMessage articleMessage = new ArticleMessage();
        articleMessage.init(objectMap);
        articleMessage.setArticleCount(articles.size() + "");
        articleMessage.setArticles(articles);
        return articleMessage;
    }

    public String toXml() {
        return XmlUtils.beanToXml(this, ArticleMessage.class);
    }

}
